package com.huawei.controller;

import com.alibaba.fastjson.JSON;
import com.huawei.entity.Lbt;
import com.huawei.service.LbtService;
import com.huawei.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName LbtController
 * @Description TODO
 * @Author zhuxin
 * @Date 2021/12/9 16:40
 */
@Controller
@RequestMapping("/lbt")
public class LbtController {
    @Resource
    LbtService lbtService;
    @RequestMapping(value = "/chaxun", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String cha(@RequestParam("page") Integer page,
                      @RequestParam("limit") Integer limit,
                      @RequestParam(value="zhuangtai",required = false)String zhuangtai
    ) {
        Map<String, Object> map = new HashMap<>();
        map.put("offset", (page-1)*limit);
        map.put("limit", limit);
        map.put("zhuangtai",zhuangtai);
        List<Lbt> list = lbtService.lbtchaxun(map);
        int count = lbtService.count(map);
        Result rs = new Result(0, "查询成功", count, list);

        return JSON.toJSONString(rs);
    }

    @RequestMapping(value = "/add", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String  ins(Lbt lbt) {
        int i = lbtService.ins(lbt);
        if (i == 1) {
            return "添加成功";
        } else {
            return "添加失败";
        }
    }
    @RequestMapping(value = "/update", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String  upd(Lbt lbt){
        int i=lbtService.upd(lbt);
        if (i==1){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
    @RequestMapping(value = "/updatezt", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String  updzt(Lbt zhuangtai){
        int i=lbtService.updzt(zhuangtai);
        if (i==1){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
    @RequestMapping(value = "/delete", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String  del(int id){
        int i=lbtService.del(id);
        if (i==1){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }
}
